<?php
if(!function_exists("form_generate")) {
	function form_generate($config) {
		/**
		 * 0 - 容器属性
		 * 1 - form的属性 [id,name]
		 * 2 - fieldset名称
		 * 3 - 字段 名称,属性
		 * 4 - 提交按钮文字
		 */
		$html[] = '<div class="form-base" id="'.$config['base'].'_con">';
		if($config['type'] == 'data') {
			$func = "form_open";
		} else {
			$func = "form_open_multipart";
		}
		$html[] = $func("http://".site_url($config['action']),array("id"=>$config['base'].'_con_form',"name"=>$config['base'].'_con_form'),$config['hidden']='');
		$html[] = form_fieldset($config['title']);

		foreach($config['fields'] as $field) {
			$html[] = '<p>';
			$html[] = form_label(ucfirst(str_replace("-"," ",$field['name'])),strtolower($field['name']));
			if($field['type'] == 'text') {
				$html[] = form_input($field);
			} else if($field['type'] == 'file') {
				$html[] = form_upload($field);
			}
			$html[] = '</p>';
		}
		$html[] = '<p>';
		$html[] = form_submit("",$config['title']);
		$html[] = '</p>';
		$html[] = form_fieldset_close();
		$html[] = form_close();
		$html[] = '</div>';
		return implode($html);
	}
}
?>